<!DOCTYPE html>
<html>

<head>

    {include file="public:header"}
</head>

<body style="color:#333;padding:3px;">
<!-- 标题 -->
<div class="page-heade">
    <h1 class="title_color">添加仓库</h1>
</div>
<!-- 标题 -->
<div>
    <form action="" class="form-inline">
        <table class="row-margin-top tab-content table-bordered table text-left" border="1">
            <tr>
                <td colspan="4" class="colorRed font-bold">注意：修改仓库简称慎重，因为修改仓库简称会导致已使用该仓库简称的地方自动变成修改后的仓库简称</td>
            </tr>
            <tr>
                <td style="min-width: 140px;width:140px" class="text-right"><label for="" class="form-label">仓库号<span
                        class="colorRed">*</span>：</label></td>
                <td><input type="text" class="form-control" name="ckh" value="{:isset($data.ckh)?$data.ckh:''}" id="cangku_num"></td>
                <td style="min-width: 140px;width:140px" class="text-right"><label for="" class="form-label">仓库简称<span
                        class="colorRed">*</span>：</label></td>
                <td><input type="text" class="form-control" name="ckjc"  value="{:isset($data.ckjc)?$data.ckjc:''}" id="cangkuName"></td>
            </tr>
            <tr>
                <td style="min-width: 140px;width:140px" class="text-right"><label for="" class="form-label">仓库联系人<span
                        class="colorRed">*</span>：</label></td>
                <td><input type="text" class="form-control" name="cklxr" value="{:isset($data.cklxr)?$data.cklxr:''}" id="cangku_concact"></td>
                <td style="min-width: 140px;width:140px" class="text-right"><label for="" class="form-label">仓库联系电话：
                </label></td>
                <td><input type="text" class="form-control" name="cklxdh" value="{:isset($data.cklxdh)?$data.cklxdh:''}"></td>
            </tr>
            <tr>
                <td style="min-width: 140px;width:140px" class="text-right"><label for="" class="form-label">仓库全称<span
                        class="colorRed">*</span>：</label></td>
                <td colspan="3"><input type="text" class="form-control" name="ckqc" value="{:isset($data.ckqc)?$data.ckqc:''}" id="cangku_allN"></td>
            </tr>
            <tr>
                <td style="min-width: 140px;width:140px" class="text-right"><label for="" class="form-label">仓库地址<span
                        class="colorRed">*</span>：</label></td>
                <td colspan="3"><input type="text" class="form-control" name="ckdz" value="{:isset($data.ckdz)?$data.ckdz:''}" id="cangku_addr"></td>
            </tr>
            <tr>
                <td style="min-width: 140px;width:140px" class="text-right"><label for="" class="form-label">仓库管理员：</label></td>
                <td colspan="3">
                    <div class="col-xs-8">
                        <div class="input-group">
                            <input name="stuff" id="cangku_man" type="text" placeholder="请输入关键字或空格查询"
                                   class=" form-control" value="">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <a href="javascript:;" id="select" class="btn btn-default btn-outline">选择</a>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px;width:140px" class="text-right">&nbsp;</td>
                <td id="renyuan" class="duoxuan">
                    {if isset($data.ckgly)}
                    {volist name="data.ckgly" id="row" key="k"}
                    <span class="ren"><input type="hidden" name="ckgly[]" value="{$row.id}">{$row.title}<span class="close">×</span></span>
                    {/volist}
                    {/if}
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px;width:140px" class="text-right" rowspan="2"><label for=""
                                                                                               class="form-label">备注：</label>
                </td>
                <td colspan="3">
                    <textarea name="bz" id="" style="user-select:none;width: 70%;height: 70px;"
                              class="form-control">{:isset($data.bz)?$data.bz:''}</textarea><span style="vertical-align: bottom;">(500)</span>
                </td>
            </tr>
        </table>
        <div class="form-group white-bg" style="margin:20px 10px 20px 20px;" id="upfileDiv">
            {if isset($attach)}
            <ul class="list-group">
                {volist name="attach" id="row"}
                <li class="list-group-item">
                    <a class="badge badge-primary removeIt" data-id="{$row.id}">移除</a>
                    <a href="{$row.path}" target="_blank">{$row.file_name}</a></li>
                {/volist}
            </ul>
            {/if}
            <div id="uploader" class="wu-example">
                <!--用来存放文件信息-->
                <div id="thelist" class="uploader-list"></div>
                <div class="btns">
                    <div id="picker">选择文件</div>
                    <button id="ctlBtn" class="btn btn-default">开始上传</button>
                </div>
                <input type="hidden" name="attach" id="attach">
                <input type="hidden" name="remove" id="remove">
            </div>
            <span>注：最多上传15个文件，每个文件小于50M,支持格式：</span><br>jpg,bnp,gif,png,jpeg,tif,raw,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,rar,zip,mp4,avi,rmvb,rm,mid,3gp,AVI,3GP,,mpg,mp3,wma,wav
        </div>
        <div class="text-center">
            <button class="btn btn-warning" id="save" type="button">保存</button>
            <button class="btn btn-success" type="button" style="margin-left: 20px" onclick="back()">返回</button>
        </div>
    </form>
</div>
<!-- 全局js -->
<script src="__STATIC__/layout/js/jquery.min.js?v=2.1.4"></script>
<script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
<script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
<script src="__STATIC__/layout/js/common.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script>
    $('.duoxuan').on('click','.close',function () {
        $(this).closest('.ren').remove()
    })
    $("#cangku_man").bsSuggest({
        url: "{:url('bs/employee')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias: {title: "人员"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onDataRequestSuccess', function (e, result) {
        console.log('onDataRequestSuccess: ', result);
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#renyuan .ren').each(function (idx, o) {
            if ($(this).data('id') == keyword.id) {
                bool = true;
            }
        })
        if (bool == false)
            $('#renyuan').append('<span class="ren" data-id="' + keyword.id + '"><input type="hidden" name="ckgly[]" value="'+keyword.id+'" />' + keyword.key + '<span class="close">×</span></span>')
        //console.log('onSetSelectValue: ', keyword, data);
    }).on('onUnsetSelectValue', function () {
        console.log("onUnsetSelectValue");
    });

    //弹窗选择人员
    $('#select').on('click', function () {
        var index = layer.getFrameIndex(window.name)
        //iframe层-父子操作
        top.layer.open({
            type: 2,
            title: '请选择',
            area: ['500px', '400px'],
            fixed: false, //不固定
            maxmin: true,
            content: '{:url("open/product")}?frameindex=' + index,
            btn:['确定','取消'],
            yes:function (i,o) {
                var a = $(o).find('iframe').contents()
                var data = a.find('#data')
                data = data.val()
                data = JSON.parse(data)
                var bool = false
                for(var j=0;j<data.length;j++){
                    $('#renyuan .ren').each(function (idx, o) {
                        if ($(this).data('id') == data[j].id) {
                            bool = true;
                        }
                    })
                    if (bool == false)
                        $('#renyuan').append('<span class="ren" data-id="' + data[j].id + '"><input type="hidden" name="ckgly[]" value="'+data[j].id+' />' + data[j].title + '<span class="close">×</span></span>')

                }
                top.layer.close(i)

            }
        });
        return false
    })

    $("#save").click(function () {
        if ($("#cangku_num").val() == "") {
            swal("", "仓库号不能为空！", "error");
        } else if ($("#cangkuName").val() == "") {
            swal("", "仓库简称不能为空！", "error");
        } else if ($("#cangku_concact").val() == "") {
            swal("", "仓库联系人不能为空！", "error");
        } else if ($("#cangku_allN").val() == "") {
            swal("", "仓库全称不能为空！", "error");
        } else if ($("#cangku_addr").val() == "") {
            swal("", "仓库地址不能为空！", "error");
        } else {
            var param = $(this).closest('form').serialize()
            $.post('',param,function (data) {
                if(data.success){
                    swal({title:data.msg},function () {
                        location.href='{:url("kcgl/cangkugl")}'
                    })
                }else{
                    swal(data.msg,'','error')
                }
            },'json')
            return false;
        }
    })


</script>
</body>

</html>
<script src="__STATIC__/layout/js/plugins/webuploader/webuploader.min.js"></script>
<script>
    // 文件上传
    jQuery(function() {
        var $ = jQuery,
            $list = $('#thelist'),
            $btn = $('#ctlBtn'),
            state = 'pending',
            uploader;

        var ids = [];
        uploader = WebUploader.create({

            // 不压缩image
            resize: false,

            // swf文件路径
            swf: BASE_URL + '/js/Uploader.swf',

            // 文件接收服务端。
            server: '{:url("upload/fileupload")}',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker'
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            $list.append( '<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>' );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo( $li ).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css( 'width', percentage * 100 + '%' );
        });

        uploader.on( 'uploadSuccess', function( file,response) {
            if(response.success)
                ids.push(response.id)
            $( '#'+file.id ).find('p.state').text(response.msg);
        });

        uploader.on( 'uploadError', function( file ) {
            $( '#'+file.id ).find('p.state').text('上传出错');
        });

        uploader.on( 'uploadComplete', function( file ) {
            $('#attach').val(ids.join(','))
            $( '#'+file.id ).find('.progress').fadeOut();
        });

        uploader.on( 'all', function( type ) {
            if ( type === 'startUpload' ) {
                state = 'uploading';
            } else if ( type === 'stopUpload' ) {
                state = 'paused';
            } else if ( type === 'uploadFinished' ) {
                state = 'done';
            }

            if ( state === 'uploading' ) {
                $btn.text('暂停上传');
            } else {
                $btn.text('开始上传');
            }
        });

        $btn.on( 'click', function() {
            if ( state === 'uploading' ) {
                uploader.stop();
            } else {
                uploader.upload();
            }
            return false
        });

    });
</script>